/**
 * 
 */
package com.gragra.sampling.nonproj.generators;
import java.io.BufferedReader;
import java.io.IOException;
import com.gragra.data.MixingCorpus;
import com.gragra.data.MixingCorpusBaseImplementation;
import com.gragra.sampling.binary.ConvertSample;
import com.gragra.sampling.binary.ConverterFactory;
import com.gragra.sampling.binary.MakeCorpus;
import com.gragra.sampling.nonproj.structures.nonprojective.NonProjDepdTree;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.EmptySegmentation;
/**
 * @author Christoph Teichmann
 * 19.08.2013
 */
public abstract class CreateDependencyCorpus implements MakeCorpus
{
	/**
	 * 
	 * @return
	 */
	protected ConvertSample makeConverter()
	{return cf.getNewConverter();}
	/**
	 * 
	 */
	private final ConverterFactory cf;
	/**
	 * @param cf
	 */
	public CreateDependencyCorpus(ConverterFactory cf)
	{
		super();
		this.cf = cf;
	}
	/**
	 * 
	 */
	private final BaseGenerator bg = new BaseGenerator(new EmptySegmentation());
	/**
	 * 
	 * @param line
	 * @param smoothing 
	 * @param threads 
	 * @return
	 */
	public NonProjDepdTree makeTree(String line, int threads, double smoothing)
	{
		WordAndTagHolder wth = bg.transferSingle(line);
		return makeTree(wth,threads,smoothing);
	}
	/**
	 * 
	 * @param intArr
	 * @return
	 */
	protected abstract NonProjDepdTree makeTree(WordAndTagHolder wth,int threads, double smoothing);
	/**
	 * 
	 * @param br
	 * @param smoothing 
	 * @return
	 * @throws IOException 
	 */
	public MixingCorpus<NonProjDepdTree> createCorpus(BufferedReader br, int threads, double smoothing) throws IOException
	{
		MixingCorpus<NonProjDepdTree> ret = new MixingCorpusBaseImplementation<NonProjDepdTree>();
		String line;
		while((line = br.readLine()) != null)
		{ret.addData(this.makeTree(line,threads,smoothing));}
		return ret;
	}
}